package com.fhx.core.utils

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.fhx.core.base.BaseFragment
import java.io.Serializable

class IntentBuilder() {

    private var intent: Intent? = null
    private var mContext: Context? = null

    constructor(context: Context, cls: Class<*>?) : this() {
        mContext = context
    }

    init {
        intent = Intent()
    }

    companion object {
        fun builder(): IntentBuilder {
            return IntentBuilder()
        }
    }

    fun setClass(
        packageContext: Context,
        cls: Class<*>
    ): IntentBuilder? {
        mContext = packageContext
        intent?.setClass(mContext!!, cls)
        return this
    }

    fun putExtra(
        name: String?,
        value: Serializable?
    ): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(
        name: String?,
        value: BooleanArray?
    ): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(name: String?, value: ByteArray?): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(
        name: String?,
        value: ShortArray?
    ): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(name: String?, value: CharArray?): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(name: String?, value: IntArray?): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(name: String?, value: LongArray?): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(
        name: String?,
        value: FloatArray?
    ): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(
        name: String?,
        value: DoubleArray?
    ): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(
        name: String?,
        value: Array<String?>?
    ): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(
        name: String?,
        value: Array<CharSequence?>?
    ): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtra(name: String?, value: Bundle?): IntentBuilder? {
        intent!!.putExtra(name, value)
        return this
    }

    fun putExtras(src: Intent?): IntentBuilder? {
        intent!!.putExtras(src!!)
        return this
    }

    fun putExtras(extras: Bundle?): IntentBuilder? {
        intent!!.putExtras(extras!!)
        return this
    }

    fun start(){
        mContext?.startActivity(intent!!)
    }

    fun start(requestCode:Int){
        (mContext as Activity).startActivityForResult(intent!!,requestCode)
    }

    fun start(fragment:BaseFragment){

    }
}